int calculate(string expr) {
    if (expr.empty()) {
        return 0;
    }
    
    vector<string> tokens;
    istringstream iss(expr);
    string token;
    while (getline(iss, token, 'x')) {
        tokens.push_back(token);
    }

    int result = 1;
    for (string& t : tokens) {
        if (t.find('#') == string::npos) {
            // 子表达式不含加法，直接转为整数
            result *= stoi(t);
        } else {
            // 处理含加法的子表达式：分割数字并求和
            istringstream iss_inner(t);
            string num;
            int sum = 0;
            while (getline(iss_inner, num, '#')) {
                sum += stoi(num);
            }
            result *= sum;
        }
    }
    return result;
}